Ext.define('AM.view.EmpfinaceView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.empfinaceView',
		store : 'EmpFinaceStore',
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'), 
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"  //"SINGLE"/"SIMPLE"/"MULTI"
	       
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
        xtype: 'pagingtoolbar',
        dock: 'bottom',
        store : 'EmpFinaceStore',
        displayInfo: true
        },{
	     dock: 'top',
	     xtype: 'toolbar',
	     items: [ {
	        xtype:'datefield',
	        format:'Y-m', 
	        labelWidth:30,
	        fieldLabel: '日期',
	        id:'empfinace_date',
	        width : 200
	      },'-',{
		     xtype : "combobox",
		     allowBlank:false,
		     emptyText:'请选择科室',
			 selectOnFocus:true,
			 forceSelection: true,
			 queryMode: 'local',
			 labelWidth:30,
			 fieldLabel: '科室',
			 name: 'searchdepartment',
			 store :Ext.create('AM.store.TargetDepartStore'),
			 displayField: 'name',
			 valueField: 'id',
			 id:'empfinace_dept',
	         width : 200,
	         listeners:{   
					select:function(combo, record,index){
								 try{ 
								 var rewar;
								 var date=Ext.getCmp('empfinace_date').getValue();
								 var date1=Ext.util.Format.date(date, 'Y-m');
								 Ext.Ajax.request({
										url : 'departmentFinaceAction_deptfinace',
									    async : false,
										success : function(response, options) {
											var re =Ext.JSON.decode(response.responseText);
											rewar=re.rewad;
										},
										failure : function() {
											Ext.MessageBox.alert("提示", "科室本月无测算奖金！");
										},
										params : {
											dept:this.value,
											searchdate:date1
										}
									});	
									 var parent=Ext.getCmp('empfinace_reward');
									 parent.reset();
									 parent.setValue(rewar);													 
								 }
								 catch(ex){
									 Ext.MessageBox.alert("错误","数据加载失败。");
								 }
							}
					}
	      },'-', {
	          xtype:'numberfield', 
			  minValue: 0,
			  fieldLabel: '科室奖金',
			  labelWidth:60,
			  readOnly:true,
			  labelAlign :"right",
		      name: 'totalReward',
		      nanText:"输入必须为数字",
		      id:'empfinace_reward',
	          width :200
	      },'-', {
	            xtype: 'button',
	            text: '计算奖金',
	            icon : 'Ext/restful/images/find.png',
	            margin: '0 0 0 5',
	            handler: function () {
	            	
	                 var department= Ext.getCmp('empfinace_dept').getValue(); //获取文本框值
	                 var  reward = Ext.getCmp('empfinace_reward').getValue();
	                 var searchdate1 = Ext.getCmp('empfinace_date').getValue();
	                 var grid=this.ownerCt.ownerCt;
	                  Ext.Ajax.request({
										url : 'performance_CountEmpPerformance',
										success : function() {
											 	grid.getStore().on('beforeload', function (store, options) {
			                                    var new_params = { searchdepart:department, searchdate:Ext.util.Format.date(searchdate1, 'Y-m')};
			                                    Ext.apply(store.proxy.extraParams, new_params);
			                                    });
			                                    grid.getStore().reload();
											},
										failure : function() {
														Ext.MessageBox.alert("提示", "计算失败，请检查是否进行本月人员考评！");
									    	},
									   params:{searchdate:Ext.util.Format.date(searchdate1, 'Y-m'),
									   		   searchdepartment:department,
									   		   totalReward:reward
									   		}
									});	
	                 
	                 
	                }
	        },{
	        	xtype: 'button',
	            text: '导出奖金',
	            icon : 'Ext/restful/images/down2.png',
	            margin: '0 0 0 15',
	            handler: function () {
//	                 var department= Ext.getCmp('empfinace_date').getValue(); //获取文本框值
	                 var searchdate = Ext.util.Format.date(Ext.getCmp('empfinace_date').getValue(), 'Y-m');
	                 window.location.href ="exportEmpfinaceAction?searchdate="+searchdate+" ";
	       		 }
	       }
	       ]
        }],
		columns: [
			        { text: 'ID', dataIndex: 'id',width:0,align:'center'},
			        //{text: '序号', xtype: 'rownumberer',width:50,align:'center'},
			        {text: '序号',  xtype: 'rownumberer',width:50,align:'center',tdCls:'background-color: #8EE5EE;'},
			        { text: '姓名', dataIndex: 'employee', width:70,align:'center'},
			        { text: '应发总奖金', dataIndex: 'reward', width:100,align:'center',xtype:'numbercolumn', format:'0.00'},
			   		{ text: '科室', dataIndex: 'department', width:100,align:'center'},
			        { text: '日期', dataIndex: 'date',width:100,align:'center'}
			        
			     ]

})

	